SoftMax


SoftMax

The SoftMax function squashes the outputs for each neuron to be between 0 and 1 such that the total sum of the outputs is equal to one. The SoftMax function produces outputs that resembles probabilities. That is, each output of the networks produces a probability value between zero and one while the summation of these probability values is one. Consequently, it is used in classification problems, that is, in problems where the input data are required to be organized (separated) in clusters. The SoftMax function is used always in the output layer of an artificial neural network for classification. When writing code to implement the SoftMax functions, it is very important to note that the exponential of a value can become very high very easily. One simple method to correct this problem is to clip the values before computing the exponential function. However, clipping introduces a discontinuity that can affect the training.
La función Softmax comprime las salidas de cada neurona para que estas sean de 0 y 1 de tal forma que la suma de las salidas sea igual a uno. La función de SoftMax produce salidas que se parecen a probabilidades. Esto es, cada salida de la red produce una probabilidad entre cero y uno mientras que la suma de estas probabilidades es uno. Consecuentemente, esa es usada en problemas de clasificación, esto es, en problemas dónde los datos de entrada se requieren organizar (separar) en grupos. La función SoftMax es usada siempre en la capa de salida de una red neuronal para clasificación. Cuando se escribe código para implementar la función SoftMax, es muy importante notar que la exponencial de un valor puede ser muy grande fácilmente. Un método simple para corregir este problema es recortar los valores antes de calcular la función exponencial. Sin embargo, el recorte introduce una discontinuidad que puede afectar el entrenamiento.

Softmax

Problem 1
Suppose that the ANN is using the SoftMax function. Compute the output of the artificial neural network.
  1. Manually or using Microsoft Excel
  2. Using Neural Lab and a Convolutional Neural Network
  3. Using Neural Lab and a Deep Learning neural network

Suponga que la ANN está usando la función SoftMax. Calcule la salida de la red neuronal artificial.
  1. Manualmente o usando Microsoft Excel
  2. Usando Neural Lab y una red neuronal convolucional
  3. Usando Neural Lab y una red de aprendizaje profundo

SoftmaxNet

Step A
Use a piece of paper, a pen and a calculator to compute the output. Alternatively, you can use Microsoft Excel.
Use una hoja de papel, una pluma y una calculadora para calcular la salida. Alternativamente, usted puede usar Microsoft Excel.

Step B
Create a Neural Lab project called Softnet. Select the Main file only option in the new project dialog. After creating the project, use notepad to create the file w.csv as shown below. Save the file in the Softnet folder.
Cree un proyecto de Neural Lab llamado Softnet. Seleccione la opción Main file only en el diálogo de proyecto nuevo. Después de crear el proyecto, use el block de notas para crear el archivo w.csv como se muestra debajo. Guarde el archivo en la carpeta Softnet.

wcsv

Softnet\Main.lab
//_______________________________________ 1. Input
Matrix input;
input.Create(1, 3);
input[0][0] = -3.0;
input[0][1] = 10.0;
input[0][2] = 4.0;
//_______________________________________ 2. Weights
Matrix w;
w.Load();
//_______________________________________ 3. Deep Net
DeepNet deepNet;
deepNet.Create(3, 1);
deepNet.SetLayer(0, 4, 3); // SoftMax=4, neurons=3
deepNet.SetWeights(0, w); // outputLayer: layerIndex=0
Matrix deepout;
deepNet.Run(input, deepout);



deepout

Step C
Add a new file called Conv.lab to the Softnet project.
Agrega un archivo nuevo llamado Conv.lab al proyecto Softnet.

Softnet\Conv.lab
//_______________________________________ 1. Input
Matrix input;
input.Create(1, 3);
input[0][0] = -3.0;
input[0][1] = 10.0;
input[0][2] = 4.0;
Tensor ti;
ti.SetFrom(input, 1, 1, 3);
//_______________________________________ 2. Weights
Matrix w;
w.Load();
Vector bias = w.GetColVec(3);
w.DeleteCol(3);
Tensor tw;
tw.SetFrom(w, 1, 1, 3);
//_______________________________________ 3. ConvNet
ConvNet convNet;
convNet.Create(1, 1, 3, 1);
convNet.SetFullLayer(0, 4, 3); // SoftMax=4, neurons=3
convNet.SetWeights(0, tw, bias); // outputLayer> layerIndex=0
Tensor convout;
convNet.Run(ti, convout);

convout

SoftMax with numerical stability

As the exponential function can grow quickly, the following method to compute SoftMax is recommended in practice.
Como la función exponencial puede crecer muy rápidamente, el método siguiente para calcular SoftMax es recomendado en la práctica.

SoftmaxNumeric

Problem 2
Compute manually the output of the artificial neural network.
  1. Use the SoftMax original formula
  2. Use the SoftMax for numerical stability

Calcule en forma manual la salida de la red neuronal artificial.
  1. Use la fórmula original de SoftMax
  2. Use SoftMax con estabilidad numérica

ProbNum

SoftMax with optimization

Consider the output layer shown below. The three neurons in the output layer produce three output: y1, y2, y3. Suppose that we remove the weights entering neuron 3, therefore, y3 is zero. As you can see from the figure, it is possible to compute the three output values z1, z2, z3 using only two output neurons. This is, of course, because the summation of z1, z2, and z3 must be one. From a practical point of view, we can conclude that for a classification problem with N classes, the number of neurons in the output layer can be N−1.
Considere la capa de salida mostrada debajo. Las tres neuronas en la capa de salida producen tres salidas: y1, y2, y3. Suponga que se remueven los pesos que entran a la neurona 3, por lo tanto, y3 vale cero. Como se puede ver de la figura, es posible calcular los tres valores de salida z1, z2, z3 usando solamente dos neuronas de salida. Esto es, por su puesto, porque la suma de z1, z2 y z3 debe ser uno. Desde un punto de vista práctico, se puede concluir que para un problema de clasificación con N clases, el número de neuronas en la capa de salida puede ser N−1.

SoftmaxOptimization

Problem 3
Compute manually the output of the artificial neural network using SoftMax with optimization.
Calcule en forma manual la salida de la red neuronal artificial usando SoftMax con optimización.

OptiProb

Problem 4
In the network show below
  1. Proof that z1 is the logsig function of y1
  2. Proof that z2 is one minus the logsig function of y1

En la red mostrada
  1. Demuestre que z1 es la función logística de y1
  2. Demuestre que z2 es uno menos la función logística 1

SoftmaxLogsig

SoftMax with optimization and numerical stability

The figure below shows how to compute the SoftMax function using one zero input and with numerical stability.
La figura de abajo muestra cómo calcular la función SoftMax usando una entrada cero y con estabilidad numérica.

SoftmaxNumericOpti

Problem 5
Repeat the problem 3 using SoftMax with optimization and numerical stability.
Repita el problema 3 usando SoftMax con optimización y estabilidad numérica.

Problem 6
Compute manually the values of z1, z2, z3, z4.
  1. Using SoftMax with optimization
  2. Using SoftMax with optimization and numerical stability

Calcule en forma manual los valores de z1, z2, z3, z4.
  1. Usando SoftMax con optimización
  2. Usando SoftMax con optimización y estabilidad numérica

DirectComputation

Problem 7
Compute manually the values of y1, y2, y3, y4, y5 to produce the output shown in the figure.
Calcule manualmente los valores de y1, y2, y3, y4, y5 para producir los valores mostrados en la figura.

SoftmaxProb

Softmax Inverse Function

The figure below shows how to compute the values of y1, y2 using the values of z1, z2, z3.
La figura de abajo muestra cómo calcular los valores de y1, y2 usando los valores de z1, z2, z3.

SoftmaxInverse

Problem 8
Compute manually the values of y1, y2, y3, y4 to produce the output shown in the figure. Verify your answer by computing back the values of z1, z2, z3, z4, z5.
Calcule manualmente los valores de y1, y2, y3, y4 para producir los valores mostrados en la figura. Verifique su respuesta calculando de regreso los valores de z1, z2, z3, z4, z5.

SoftmaxOneZeroProb

Problem 9
Compute manually the values of y1, y2, y3, y4, y5 to produce the output shown in the figure. Verify your answer by computing back the values of z1, z2, z3, z4, z5.
Calcule manualmente los valores de y1, y2, y3, y4, y5 para producir los valores mostrados en la figura. Verifique su respuesta calculando de regreso los valores de z1, z2, z3, z4, z5.

SoftmaxOneZeroProbX

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home